package com.zretc.entity;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author 周文涛
 * 2020年8月19日20:23:27
 * 用户实体类
 */
public class UserInfo implements UserDetails {

    private Integer userId; // 用户编号
    private String userName; // 用户账号
    private String userPassword; // 用户密码
    private String name; // 用户名称
    private String phone; // 用户电话
    private String telephone; // 用户座机
    private String address; // 用户地址
    private boolean enabled; // 是否启用账号： 0未启用 1已启用
    private String userFace; // 用户头像
    private String remark; // 备注

    // 用户包含的角色
    private List<Role> roles;

    public List<Role> getRoles() {
        return roles;
    }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public UserInfo() {
    }

    public Integer getUserId() {
            return userId;
    }

    public void setUserId(Integer userId) {
            this.userId = userId;
    }

    public String getUserName() {
            return userName;
    }

    public void setUserName(String userName) {
            this.userName = userName;
    }

    public String getUserPassword() {
            return userPassword;
    }

    public void setUserPassword(String userPassword) {
            this.userPassword = userPassword;
    }

    public String getName() {
            return name;
    }

    public void setName(String name) {
            this.name = name;
    }

    public String getPhone() {
            return phone;
    }

    public void setPhone(String phone) {
            this.phone = phone;
    }

    public String getTelephone() {
            return telephone;
    }

    public void setTelephone(String telephone) {
            this.telephone = telephone;
    }

    public String getAddress() {
            return address;
    }

    public void setAddress(String address) {
            this.address = address;
    }

    public void setEnabled(Boolean enabled) {
            this.enabled = enabled;
    }

    public String getUserFace() {
            return userFace;
    }

    public void setUserFace(String userFace) {
            this.userFace = userFace;
    }

    public String getRemark() {
            return remark;
    }

    public void setRemark(String remark) {
            this.remark = remark;
    }

    @Override
    public String toString() {
            return "UserInfo{" +
                    "userId=" + userId +
                    ", userName='" + userName + '\'' +
                    ", userPassword='" + userPassword + '\'' +
                    ", name='" + name + '\'' +
                    ", phone='" + phone + '\'' +
                    ", telephone='" + telephone + '\'' +
                    ", address='" + address + '\'' +
                    ", enabled=" + enabled +
                    ", userFace='" + userFace + '\'' +
                    ", remark='" + remark + '\'' +
                    '}';
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<SimpleGrantedAuthority> authorities = new ArrayList<>(roles.size());
        for (Role role : roles) {
            authorities.add(new SimpleGrantedAuthority(role.getRoleName()));
        }
        return authorities;
    }

    @Override
    public String getPassword() {
        return userPassword;
    }

    @Override
    public String getUsername() {
        return userName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }
}
